package com.nari.ies.ne.nw.server.service.fileScore.impl;

import com.nari.ies.ne.nw.server.entity.PvFileScoreEntity;
import com.nari.ies.ne.nw.server.entity.WindFileScoreEntity;
import com.nari.ies.ne.nw.server.mapper.FileScoreMapper;
import com.nari.ies.ne.nw.server.service.fileScore.IFileScoreService;
import com.nari.ies.ne.nw.server.service.fileScore.INBQHLXFileScoreService;
import com.nari.ies.ne.nw.server.util.DataUtil;
import com.nari.ies.ne.nw.server.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class NBQHLXFileScoreServiceImpl implements INBQHLXFileScoreService {
    @Autowired
    private IFileScoreService fileScoreService;
    @Autowired
    private FileScoreMapper fileScoreMapper;
    @Override
    public PvFileScoreEntity NBQHLXFileScore(PvFileScoreEntity pvFileScoreEntity) {
        String plantId = pvFileScoreEntity.getPlantId();
        //今天00:00
        Date endDate = pvFileScoreEntity.getDateTime();
        Date startDate = DateUtil.getYesterdayTime(endDate);
        String fileType = "NBQ-HLX";
        String plantType = "GF";
        String tableName="HISDB.NW_NE_FILE_DATACHECK_GF_NBQHLX";

        //上送文件数量
        int NBQ_HLXNum = fileScoreMapper.selectFileNumData(tableName,plantId, fileType, plantType, startDate, endDate);
        //文件满分
        float NBQ_HLXFullScore = fileScoreMapper.selectFileFullScore(fileType, plantType);
        //完整率
        float NBQ_HLXRate = 0;
        //文件上送率
        float NBQ_HLXSendRate = 0;
        //文件得分
        float NBQ_HLXScore = 0;
        //文件合格率
        float NBQ_HLXQualifiedRate = 0;


        if (NBQ_HLXNum > 0) {
            //文件上送率
            NBQ_HLXSendRate = 100;
            NBQ_HLXRate = (float) NBQ_HLXNum / 96 * 100;
            //文件数据项总得分
            float fileDataScore = fileScoreService.getFileDataScore(plantId, fileType, plantType, startDate, endDate,tableName);
            //文件得分
            NBQ_HLXScore = fileDataScore;
            //文件合格率
            NBQ_HLXQualifiedRate = NBQ_HLXScore / NBQ_HLXFullScore * 100;
        }else {
            NBQ_HLXRate=0;
            NBQ_HLXScore=0;
            NBQ_HLXSendRate=0;
            NBQ_HLXQualifiedRate=0;
        }
        pvFileScoreEntity.setNBQ_HLXNum(NBQ_HLXNum);
        pvFileScoreEntity.setNBQ_HLXRate(NBQ_HLXRate);
        pvFileScoreEntity.setNBQ_HLXScore(NBQ_HLXScore);
        pvFileScoreEntity.setNBQ_HLXFullScore(NBQ_HLXFullScore);
        pvFileScoreEntity.setNBQ_HLXQualifiedRate(NBQ_HLXSendRate);
        pvFileScoreEntity.setNBQ_HLXSendRate(NBQ_HLXQualifiedRate);

        return pvFileScoreEntity;
    }
}
